import my.mall.admin.api.AdminApplication
import my.mall.admin.api.service.DictionaryService
import my.mall.db.entity.Dictionary
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest(classes = [AdminApplication::class])
class DictionaryServiceTest {

    @Autowired
    private lateinit var dictionaryService: DictionaryService

    /**
     * 测试rewriteBatchedStatements参数对批量插入性能的影响
     * 测试结果：不添加该参数10万条数据插入需要10分钟左右，添加该参数后只需要不到10秒
     */
    @Test
    fun testBatchInsert() {
        val dictList = ArrayList<Dictionary>()
        for (i in 0 until 100000) {
            val dict = Dictionary()
            dict.dictKey = "test$i"
            dict.dictValue = "test$i"
            dictList.add(dict)
        }
        val startTime = System.currentTimeMillis()
        dictionaryService.saveBatch(dictList)
        println("耗时：${System.currentTimeMillis() - startTime}ms")
    }
}